<?php

namespace App\Controller\Pay;

use App\Constants\CodeData;
use App\Controller\BaseController;
use App\Exception\MessageException;
use App\Request\Pay\CreatePayOrderRequest;
use App\Request\Pay\PayProductListRequest;
use App\Services\Pay\PaySevice;
use App\Utils\LoggerUtil;
use Hyperf\Context\Context;
use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;

class PayController extends BaseController
{
    #[Inject]
    public PaySevice $paySevice;


    /**
     * Note - 获取支付产品列表
     * DateTime 2024/8/23 14:41
     * User Admin
     * @param PayProductListRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function payProductList(PayProductListRequest $request)
    {
        $params = $this->request->post();
        $params['language'] = Context::get('language');
        $request->execute($params);
        $user = Context::get('user');
        $list = $this->paySevice->payProductList($user, $params);
        return $this->return($list);
    }


    /**
     * Note - 创建苹果支付订单
     * DateTime 2024/8/23 14:41
     * User Admin
     */
    public function createPayOrder(CreatePayOrderRequest $request)
    {
        $params = $this->request->post();
        $params['language'] = Context::get('language');
        $request->execute($params);
        $user = Context::get('user');
        $res = $this->paySevice->createPayOrder($user, $params);
        return $this->return($res);

    }

}